#!/bin/csh -f

# NB: Put the finished completions in the gromacs-x.y.z/scripts directory.

if ( $#argv < 1 ) then
  echo "Error: provide the binary directory as first argument."
  echo "Completions will be written in the current directory."
  exit
endif

set GMXBINDIR = $1

set out = completion
set dir = $cwd

echo Generating completions for csh, bash and zsh

if ( -f $out.csh) then
  rm $out.csh 
endif
if ( -f $out.bash) then
  rm $out.bash 
endif
if ( -f $out.zsh) then
  rm $out.zsh 
endif

touch $out.csh $out.bash $out.zsh

cd $GMXBINDIR
set PROGRAMS = [a-z]*
cd $dir

foreach program ( $PROGRAMS )
  if ( ( -x $GMXBINDIR/$program ) && ( $program != "my_dssp" )  && ( $program != "average" ) && ( $program != "GMXRC" ) && ( $program != "completion.zsh" ) && ( $program != "completion.csh" )  && ( $program != "completion.bash" ) && ( $program != "luck" ) ) then
    $GMXBINDIR/$program -man completion >& /dev/null
    cat $program.completion-csh >> $out.csh
    cat $program.completion-bash >> $out.bash
    cat $program.completion-zsh >> $out.zsh
    \rm $program.completion-csh $program.completion-bash $program.completion-zsh 
  endif
end

#last line

